import asyncio
import aiohttp


class RequestsByAsync:
    def __init__(self,
                 request_method: str = None,
                 url_list: list = None,
                 headers: dict = None,
                 cookies: dict = None,
                 params: dict = None,
                 callback=None,
                 ):
        self.__request_method = request_method
        self.__url_list = url_list
        self.__headers = headers
        self.__cookies = cookies
        self.__params = params

        self.callback = callback

    async def __request(self, url):
        async with aiohttp.ClientSession() as session:
            if self.__request_method.lower() == "get":
                async with session.get(url, headers=self.__headers, cookies=self.__cookies,
                                       params=self.__params) as response:
                    await self.callback(response)
                    return

            if self.__request_method.lower() == "post":
                async with session.post(url, headers=self.__headers, cookies=self.__cookies,
                                        data=self.__params) as response:
                    await self.callback(response)
                    return

            if self.__request_method.lower() == "put":
                pass
                return

            if self.__request_method.lower() == "delete":
                pass
                return

            if self.__request_method.lower() == "patch":
                pass
                return

            raise "please input valid request method"

    async def start(self):
        tasks = [self.__request(url) for url in self.__url_list]
        results = await asyncio.gather(*tasks)
        return results
